package cn.sdormitory.controller.school;

import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.school.entity.SchoolDuty;
import cn.sdormitory.smartclass.service.ClassDvService;
import cn.sdormitory.smartclass.vo.ClassDvAllExportVO;
import cn.sdormitory.smartclass.vo.ClassDvVo;
import com.alibaba.excel.EasyExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "School-DvInfo=> 校园违纪")
@RequestMapping("/school/dvInfo")
public class SchoolDvInfoController {

    @Autowired
    private ClassDvService classDvService;

    @ApiOperation("getClassDvPageList => 分页查询违纪")
    @PreAuthorize("@ss.hasPermi('school:classdv:query')")
    @PostMapping(value = "/getClassDvPageList")
    public CommonResult<CommonPage<ClassDvVo>> getClassDvPageList(@RequestBody Map<String, Object> params){
        return CommonResult.success(classDvService.getPage(params));
    }

    @ApiOperation("exportDutyData =>导出违纪信息")
    @GetMapping(value = "/exportDvData")
    public CommonResult exportDvData(HttpServletResponse response, @RequestParam Map<String, Object> params) {
        List<ClassDvAllExportVO> list = classDvService.exportDvData(params);
        try {
            EasyExcel.write(response.getOutputStream(), ClassDvAllExportVO.class).sheet("违纪信息").doWrite(list);
            return CommonResult.success();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return CommonResult.failed();

    }

}
